package com.michael.adapter.aspect;

import com.michael.adapter.protocol.HttpQueryProtocol;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class HttpQueryAspect {

    @Around(value = "methodPointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        try {
            HttpQueryProtocol.init();
            return point.proceed();
        } catch (Exception e) {
            throw e;
        } finally {
            HttpQueryProtocol.remove();
        }
    }

    /**
     * 切入点入口
     */
    @Pointcut("controllerPointCut()")
    public void methodPointcut() {
    }


    /**
     * controller控制层切点 - ALL
     */
    @Pointcut("execution(* com.michael.web.controller.*.*(..))")
    public void controllerPointCut() {
    }
}
